// 2025/09/23
// Author: Forever
#include <bits/stdc++.h>
using namespace std;

int n, t;
char c[105][105];

class Matrix {
public:
    int n, m, a[101][101];
    Matrix()
    {
        n = m = 0;
    }
    Matrix(int N, int M)
    {
        n = N, m = M;
        memset(a, 0, sizeof(a));
    }
    Matrix operator*(Matrix b)
    {
        Matrix c(n, b.m);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= b.m; j++)
                for (int k = 1; k <= m; k++)
                    c[i][j] += a[i][k] * b[k][j], c[i][j] %= 2009;
        return c;
    }
    int* operator[](int x)
    {
        return a[x];
    }
};

Matrix quick_pow(Matrix a, int k)
{
    Matrix ans(a.n, a.n);
    for (int i = 1; i <= a.n; i++)
        ans.a[i][i] = 1;
    while (k) {
        if (k & 1)
            ans = ans * a;
        a = a * a;
        k >>= 1;
    }
    return ans;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> t;
    for (int i = 1; i <= n; i++)
        cin >> (c[i] + 1);
    Matrix A(n * 9, n * 9);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (c[i][j] != '0')
                A[(j - 1) * 9 + 1][(i - 1) * 9 + c[i][j] - '0']++;
    for (int i = 1; i <= n * 9; i++)
        if (i % 9 != 1)
            A[i][i - 1]++;
    Matrix B = quick_pow(A, t), C(n * 9, 1);
    C[1][1] = 1;
    cout << (B * C)[(n - 1) * 9 + 1][1] << endl;
    return 0;
}